package cn.djp.canting.bean;

import org.litepal.LitePal;
import org.litepal.crud.LitePalSupport;

import java.util.List;

import cn.djp.canting.R;

public class AllFood extends LitePalSupport {
    private int id;
    private String foodName;
    private String foodContent;
    private int foodPrice;
    private int imgId;
    private int num;

    @Override
    public String toString() {
        return "AllFood{" +
                "id=" + id +
                ", foodName='" + foodName + '\'' +
                ", foodContent='" + foodContent + '\'' +
                ", foodPrice=" + foodPrice +
                ", imgId=" + imgId +
                ", num=" + num +
                '}';
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public int getImgId() {
        return imgId;
    }

    public void setImgId(int imgId) {
        this.imgId = imgId;
    }

    public AllFood(String foodName, String foodContent, int foodPrice, int imgId) {

        this.foodName = foodName;
        this.foodContent = foodContent;
        this.foodPrice = foodPrice;
        this.imgId = imgId;
    }

    //将餐厅的全部的餐品的信息添加至数据库
    public static void setOrder() {
        addDB("锅包肉", "锅包肉锅包肉锅包肉", 25,R.mipmap.guobaorou);
        addDB("宫保鸡丁", "宫保鸡丁宫保鸡丁宫保鸡丁", 25,R.mipmap.gongbaojiding);
        addDB("烤鸭", "烤鸭烤鸭烤鸭", 35, R.mipmap.kaoya);
        addDB("红烧鲫鱼", "红烧鲫鱼红烧鲫鱼红烧鲫鱼", 45, R.mipmap.hongshaojiyu);
        addDB("手抓羊扒", "手抓羊扒手抓羊扒", 50, R.mipmap.shouzhuayangpa);
        addDB("四喜丸子", "四喜丸子四喜丸子四喜丸子", 19, R.mipmap.sixiwanzi);
        addDB("碳烧生蚝", "碳烧生蚝碳烧生蚝碳烧生蚝", 29, R.mipmap.tanshaoshenghao);
    }

    //添加至数据库的方法,由setOrder()方法调用
    private static void addDB(String foodName, String foodContent, int foodPrice, int imgId) {
        //查询表中是否有该餐品,如果有,则不进行添加,如果没有则添加
        List<AllFood> foods = LitePal.where("foodName = ?", foodName).find(AllFood.class);
        if (foods.size() == 0) {
            AllFood food = new AllFood(foodName,foodContent,foodPrice,imgId);
            food.save();
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }


    public String getFoodName() {
        return foodName;
    }

    public void setFoodName(String foodName) {
        this.foodName = foodName;
    }

    public String getFoodContent() {
        return foodContent;
    }

    public void setFoodContent(String foodContent) {
        this.foodContent = foodContent;
    }

    public int getFoodPrice() {
        return foodPrice;
    }

    public void setFoodPrice(int foodPrice) {
        this.foodPrice = foodPrice;
    }

}
